﻿'use strict';
const db = uniCloud.database();

exports.main = async (event, context) => {
  console.log('=== checkDatabase 云函数开始 ===')
  
  try {
    // 检查 interaction-messages 表
    const interactionCount = await db.collection('interaction-messages').count();
    console.log('interaction-messages 表总数:', interactionCount.total);
    
    // 获取前5条数据
    const sampleData = await db.collection('interaction-messages')
      .limit(5)
      .get();
    
    console.log('前5条数据:', sampleData.data);
    
    return {
      code: 200,
      data: {
        totalCount: interactionCount.total,
        sampleData: sampleData.data
      }
    };
  } catch (error) {
    console.error(' 检查数据库失败:', error);
    return {
      code: 500,
      msg: '检查数据库失败',
      error: error.message
    };
  }
};
